package com.example.tests;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static com.example.tests.GroupDataGenerator.loadGroupsFromCsvFile;
import static com.example.tests.GroupDataGenerator.loadGroupsFromXmlFile;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

import com.example.utils.SortedListOf;

public class GruopCreationTests extends TestBase {

  @DataProvider	
  public Iterator<Object[]> groupsFromFile() throws IOException {
	return wrapGroupsForDataProvider(loadGroupsFromCsvFile(new File("groups.testdata.csv"))).iterator();
  }	

@Test(dataProvider = "groupsFromFile")
  public void testGroupCreationValidData(GroupData groupData) throws Exception {
    // save old state
    SortedListOf<GroupData> oldList = app.getGroupHelper().getGroups();
	
    // actions
	app.getGroupHelper().createGroup(groupData);
	
	// save new state
	SortedListOf<GroupData> newList = app.getGroupHelper().getGroups();
	
	// compare states
	assertThat(newList, equalTo(oldList.withAdded(groupData)));
  }
}
